<!doctype html>
<html lang="en" class="fixed">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>学生试听</title>
    <link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
    <link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
    <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
    <link rel="stylesheet" type="text/css"
          href="<?php xcho(loadSource('/assets/plugins/bootstrap/css/bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/animate.css/animate.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/font-awesome/css/font-awesome.css')) ?>">
    <link rel="stylesheet"
          href="<?php xcho(loadSource('/assets/plugins/data-table/media/css/dataTables.bootstrap.min.css')) ?>">
    <!--    <link rel="stylesheet" href="-->
    <?php //xcho(loadSource('/assets/plugins/ztree/css/zTreeStyle/zTreeStyle.css')) ?><!--">-->
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/layui/css/layui.css')) ?>" media="all">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/ztree/css/zTreeStyle/zTreeStyle.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/ztree/css/metroStyle/metroStyle.css')) ?>"
          type="text/css">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/style.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/app.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/css/new_main.css')) ?>">
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        ul, li, ol, li {
            list-style: none;
        }

        body {
            background: #f4f4f4;
        }

        .addCourse {
            width: 900px;
            margin: 0 auto;
            background: #fff;
            padding-bottom: 20px;
        }

        .addCourse .addCourse-title {
            padding: 10px 20px;
            text-align: center;
        }

        .addCourse .addCourse-content .addCourse-cont h3 {
            font-size: 12px;
            padding: 8px 10px;
            background: rgba(243, 243, 243, .5);
            margin-top: 0;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form {
            padding: 20px;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row {
            margin-top: 20px;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form .layui-form-item {
            margin: 5px 0;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form .layui-form-item label {
            font-size: 12px;
            padding: 6px;
            background: #FBFBFB;
            border: 1px #E8E8E8 solid;
            margin-left: 8px;
            width: initial;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form div {
            display: inline-block;
            margin-bottom: 0;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row p {
            float: left;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row textarea {
            resize: none;
            border-radius: 5px;
            border: 1px #ccc solid;
            text-indent: 10px;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form span {
            margin-left: 40px;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form span:nth-of-type(1) {
            margin-left: 0;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form select {
            width: 100px;
            border-radius: 5px;
            height: 24px;
            border: 1px #ccc solid;
            font-size: 12px;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form .dateInput input {
            width: 140px;
        }

        .addCourse .addCourse-content .addCourse-cont .cont-form input {
            border: 1px #ccc solid;
            text-indent: 10px;
            height: 34px;
        }

        .addCourse .addCourse-content .addCourse-cont .addCourse-btn {
            width: 100%;
            height: 40px;
            padding: 0 20px;
        }

        .addCourse .addCourse-content .addCourse-cont .addCourse-btn .addCourse-btn-cont {
            float: right;
        }

        .layui-input {
            border-radius: 0;
        }
    </style>
</head>
<body><?php include_once TPL_PATH . 'public/nav.phtml'; ?>
<div class="addCourse">
    <div class="addCourse-title"><?php xcho($aData['student_name']??'')?>试听课<span name="primary"></span><span name="all_data"></span></div>
    <div class="addCourse-content">
        <div class="addCourse-cont">
            <form action="" id="sForm">
                <h3>试听信息</h3>
                <div class="layui-form cont-form">
                    <div class="layui-form-item">
                        <input type="hidden" id="lesson_id" name="lesson_id"
                               value="<?php xcho($aData['lesson_id']??'') ?>">
                        <input type="hidden" id="instance_id" name="instance_id"
                               value="<?php xcho($aData['instance_id']??'') ?>">
                        <input type="hidden" id="student_id" name="student_id"
                               value="<?php xcho($aData['student_id']??'') ?>">
                        <input type="hidden" id="last_follow_id" name="last_follow_id"
                               value="<?php xcho($aData['last_follow_id']??'') ?>">
                        <input type="hidden" id="cellphone" name="cellphone"
                               value="<?php xcho($aData['cellphone']??'') ?>">
                        <label class="layui-form-label">试听时间：</label>
                        <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                            <input type="text" class="layui-input" name="start_date" id="start_date"
                                   value="<?php xcho($aData['start_date']??date('Y-m-d',time())) ?>"
                                   placeholder="年/月/日">
                        </div>
                        <select name="audition_times" id="audition_times">
                            <?php foreach ($aAuditionTimes as $aTmps) { ?>
                                <option value="<?php xcho($aTmps['dict_value']) ?>"
                                    <?php if ($aTmps['dict_value'] == ($aData['audition_times']??'')) { ?>
                                        selected="selected"
                                    <?php } ?>><?php xcho($aTmps['cn_name']) ?></option>
                            <?php } ?>
                        </select>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择教师：</label>
                        <input type="text" id="teacher_name" name="teacher_name"
                               value="<?php xcho($aData['teacher_name']??'') ?>" url="<?php xcho($sSearchTeacher)?>">
                        <input type="hidden" id="teacher_id" name="teacher_id"
                               value="<?php xcho($aData['teacher_id']??'') ?>">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择课程：</label>
                        <input type="text" id="course_name" name="course_name"
                               value="<?php xcho($aData['course_name']??'') ?>" url="<?php xcho($sSearchCourse)?>">
                        <input type="hidden" id="course_id" name="course_id"
                               value="<?php xcho($aData['course_id']??'') ?>">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">试听考勤：</label>
                        <select name="student_attendance_status" id="student_attendance_status" lay-filter="student_attendance_status">
                            <?php foreach ($aAttendance as $aTmps) { ?>
                                <option value="<?php xcho($aTmps['dict_value']) ?>"
                                    <?php if ($aTmps['dict_value'] == ($aData['student_attendance_status']??'')) { ?>
                                        selected="selected"
                                    <?php } ?>><?php xcho($aTmps['cn_name']) ?></option>
                            <?php } ?>
                        </select>
                        <input name="teacher_attendance_status" id="teacher_attendance_status" type="hidden"
                               value="<?php xcho($aData['student_attendance_status']??'')?>">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">教务确认：</label>
                        <select name="is_confirm" id="is_confirm">
                            <?php foreach ($aConfirm as $aTmps) { ?>
                                <option value="<?php xcho($aTmps['dict_value']) ?>"
                                    <?php if ($aTmps['dict_value'] == ($aData['is_confirm']??'')) { ?>
                                        selected="selected"
                                    <?php } ?>><?php xcho($aTmps['cn_name']) ?></option>
                            <?php } ?>
                        </select>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">热度：</label>
                        <input type="text" id="hot" name="hot" value="<?php xcho($aData['hot']??'') ?>">
                    </div>
                </div>
                <h3>同步信息</h3>
                <div class="layui-form cont-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">天王星学员ID：</label>
                        <input type="text" id="twx_id" name="twx_id"
                               value="<?php xcho($aData['twx_id']??0) ?>"
                               disabled="disabled">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">官网学员ID：</label>
                        <input type="text" id="gw_id" name="gw_id"
                               value="<?php xcho($aData['gw_id']??0) ?>"
                               disabled="disabled">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">学员账号：</label>
                        <input type="text" id="gw_account" name="gw_account"
                               value="<?php xcho($aData['gw_account']??'') ?>"
                               disabled="disabled">
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">学员密码：</label>
                        <input type="text" id="gw_password" name="gw_password"
                               value="<?php xcho($aData['gw_password']??'') ?>"
                               disabled="disabled">
                    </div>
                </div>
                <h3>备注信息</h3>
                <div class="layui-form cont-form">
                    <label class="layui-form-label">备注：</label>
                    <div class="layui-form-item">
                        <textarea type="text" id="remark" name="remark" cols="100" rows="3"><?php xcho($aData['remark']??'') ?></textarea>
                    </div>
                </div>
                <div class="addCourse-btn">
                    <div class="addCourse-btn-cont">
                        <span class="layui-btn layui-btn-primary" id="cancel">取消</span>
                        <span class="layui-btn layui-btn-normal" id="submit" url="<?php xcho($saveUrl)?>">确定</span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</div>
<script src="<?php xcho(loadSource('/assets/plugins/jquery/jquery.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layui/layui.all.js')) ?>" charset="utf-8"></script>
<script src="<?php xcho(loadSource('/assets/plugins/bootstrap/js/bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/jquery.dataTables.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/dataTables.bootstrap.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/dataTables.responsive.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script>
    layui.use(['layer', 'form', 'laydate'], function () {
        var layer = layui.layer
            , form = layui.form;
        var laydate = layui.laydate;
        var nowdate = getNowFormatDate();
        laydate.render({
            elem: '#start_date' //指定元素
            ,min: nowdate
        });
        form.on("select(student_attendance_status)", function(data){
            $("#teacher_attendance_status").attr('value',data.value);
        });
    });

    //获取当前时间，格式YYYY-MM-DD
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }

    $("#teacher_name").focus(function () {
        var index = layer.open({
            type: 2
            , title: false //不显示标题栏
            , closeBtn: false
            , area: 'auto'
            , shade: 0.8
            , id: 'LAY_layuipro' //设定一个id，防止重复弹出
            , btn: ['确定', '取消']
            , moveType: 1 //拖拽模式，0或者1
            , content: $(this).attr('url')+'?date='+$("#start_date").val()+'&times='+$("#audition_times").val()
        });
        layer.full(index);
    });
    $("#course_name").focus(function () {
        var index = layer.open({
            type: 2
            , title: false //不显示标题栏
            , closeBtn: false
            , area: 'auto'
            , shade: 0.8
            , id: 'LAY_layuipro' //设定一个id，防止重复弹出
            , btn: ['确定', '取消']
            , moveType: 1 //拖拽模式，0或者1
            , content: $(this).attr('url')
        });
        layer.full(index);
    });
    var stop = 0;
    $("#submit").click(function () {
        if(stop == 1){
            return;
        }
        stop = 1;
        $(".hidden_area").remove();
        var sUrl = $(this).attr('url');
        var iTeacherID = $("#teacher_id").val();
        var aData = {
            "gw_id":$("#gw_id").val(),
            "twx_id":$("#twx_id").val(),
        };
        $($("#sForm").serializeArray()).each(function () {
            if(aData[this.name]){
                if($.isArray(aData[this.name])){
                    aData[this.name].push(this.value);
                }else{
                    aData[this.name]=[aData[this.name],this.value];
                }
            }else{
                aData[this.name]=this.value;
            }
        })
        $.ajax({
            url: sUrl,
            data: aData,
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if(data.success==1){
                    /*$("#cancel").trigger("click");*/
                    var jumpUrl = "<?php xcho($sJumpUrl)?>"+ '&lesson_id=' + data['primary'] + '&teacher_id=' + iTeacherID;
                    location.href = jumpUrl;
                }else{
                    stop = 0;
                    $.each(data.errors,function (sKey,aVal) {
                        $("[name='"+sKey+"']").after("<span class='hidden_area' style='color: red;padding-top: 5px;'>"+aVal['message']+"</span>");
                    })
                }
            }
        })
    })
    //关闭添加课次
    $("#cancel").on("click", function () {
        window.history.back();
        //window.parent.$('#index_tabs').tabs('close', '编辑试听');
    })
</script>
<?php include_once TPL_PATH . 'public/foot_script.phtml'; ?>
<button id="top" style="height: 50px;width: 50px;"></button></body>

</html>
